﻿@page "/rich-text-editor/events"

@using Syncfusion.Blazor.RichTextEditor
@using Syncfusion.Blazor.Inputs
@using Syncfusion.Blazor.Popups

@inherits SampleBaseComponent;

<SampleDescription>
    <p>This sample demonstrates the events that trigger on every action of the Rich Text Editor. The event details are showcased in the event trace panel.</p>
</SampleDescription>
<ActionDescription>
    <p>
        The Rich Text Editor triggers the events based on its actions.
        The events can be used as an extension point to perform custom operations.
    </p>
    <ul>
        <li><code>ValueChange</code> - Triggers when the editor gets blurred and changes are made to the content.</li>
        <li><code>Focus</code> - Triggers when the editor is in focus.</li>
        <li><code>Blur</code> - Triggers when focused out of the editor.</li>
        <li><code>OnActionBegin</code> - Triggers before the execution of command.</li>
        <li><code>OnActionComplete</code> - Triggers after the execution of command.</li>
        <li><code>Created</code> - Triggers when the component is created.</li>
        <li><code>OnDialogOpen</code> – Event triggers when the dialog is being opened.</li>
        <li><code>DialogOpened</code> – Event triggers when a dialog is opened.</li>
        <li><code>OnDialogClose</code> – Event triggers when the dialog is being closed.</li>
        <li><code>DialogClosed</code> – Event triggers after the dialog has been closed.</li>
        <li><code>OnQuickToolbarOpen</code> – Event triggers when the quick toolbar is being opened.</li>
        <li><code>QuickToolbarOpened</code> – Event triggers when a quick toolbar is opened.</li>
        <li><code>QuickToolbarClosed</code> – Event triggers after the quick toolbar has been closed.</li>
        <li><code>OnImageSelected</code> – Event triggers when the image is selected or dragged into the insert image dialog.</li>
        <li><code>BeforeUploadImage</code> – Triggers when the selected image begins to upload to the server.</li>
        <li><code>ImageUploadChange</code> – Triggers when the image is successfully uploaded and the value changed in the Rich Text Editor uploader.</li>
        <li><code>OnImageUploadSuccess</code> – Event triggers when the image is successfully uploaded to the server side.</li>
        <li><code>OnImageUploadFailed</code> – Event triggers when there is an error in the image upload.</li>
        <li><code>OnImageRemoving</code> – Event triggers when the selected image is cleared from the insert image dialog.</li>
        <li><code>ImageDelete</code> – Triggers when the selected image is cleared from the Rich Text Editor content.</li>
        <li><code>Destroyed</code> – Triggers when the component is destroyed.</li>
        <li><code>OnResizeStart</code> –Triggers only when you start resizing the image.</li>
        <li><code>OnResizeStop</code> – Triggers only when you stop resizing the image.</li>
        <li><code>OnToolbarClick</code> – Triggers when the Rich Text Editor toolbar items are clicked.</li>
    </ul>
</ActionDescription>

<div class="col-lg-8 control-section">
    <div class="control-wrapper">
        <div class="sample-container">
            <div class="default-section">
                <SfRichTextEditor AutoSaveOnIdle="true" EnableResize="true">
                    <p>The Rich Text Editor component is a WYSIWYG ("what you see is what you get") editor that provides the best user experience to create and update the content. 
                        Users can format their content using the standard toolbar commands.</p>
                
                    <p><b>Key features:</b></p>
                
                    <ul>
                        <li>
                            <p>Provides &lt;IFRAME&gt; and &lt;DIV&gt; modes</p>
                        </li>
                        <li>
                            <p>Capable of handling markdown editing.</p>
                        </li>
                        <li>
                            <p>Contains a modular library to load the necessary functionality on demand.</p>
                        </li>
                        <li>
                            <p>Provides a fully customizable toolbar.</p>
                        </li>
                        <li>
                            <p>Provides HTML view to edit the source directly for developers.</p>
                        </li>
                        <li>
                            <p>Supports third-party library integration.</p>
                        </li>
                        <li>
                            <p>Allows preview of modified content before saving it.</p>
                        </li>
                        <li>
                            <p>Handles images, hyperlinks, video, hyperlinks, uploads, etc.</p>
                        </li>
                        <li>
                            <p>Contains undo/redo manager.</p>
                        </li>
                        <li>
                            <p>Creates bulleted and numbered lists.</p>
                        </li>
                    </ul>
                    <RichTextEditorEvents Created="@Created" Destroyed="@Destroyed"
                            Focus="@Focus" Blur="@Blur" ValueChange="@Change"
                            OnActionBegin="@ActionBegin" OnActionComplete="@ActionComplete"
                            OnDialogOpen="@BeforeDialogOpen" DialogOpened="@DialogOpen"
                            OnDialogClose="@BeforeDialogClose" DialogClosed="@DialogClose"
                            OnQuickToolbarOpen="@BeforeQuickToolbarOpen" QuickToolbarOpened="@QuickToolbarOpen" QuickToolbarClosed="@QuickToolbarClose"
                            OnResizeStart="@ResizeStart" OnResizeStop="@ResizeStop"
                            OnImageSelected="@OnImageSelected" BeforeUploadImage="@BeforeUploadImage" OnImageUploadFailed="@OnImageUploadFailed"
                            OnImageUploadSuccess="@OnImageUploadSuccess" ImageUploadChange="@ImageUploadChange"
                            OnImageRemoving="@OnImageRemoving" ImageDelete="@ImageDeleted"
                            OnToolbarClick="@ToolbarClick" />
                    <RichTextEditorToolbarSettings Items="@Items" />
                </SfRichTextEditor>
            </div>
        </div>
    </div>
</div>
<div class="col-lg-4 property-section">
    <div class="property-panel-section">
        <div class="property-panel-header">Event Trace</div>
        <div class="property-panel-content">
            <table id="property" title="Event Trace" class="property-panel-table">
                <tbody>
                    <tr>
                        <td>
                            <div class="eventarea" style="height: 245px;overflow: auto">
                                <div class="EventLog" id="EventLog" style="word-break: normal;">
                                    <span>@((MarkupString)Output)</span>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div class="evtbtn" style="padding-bottom: 10px">
                                <button class="e-btn e-outline" @onclick="ClearLog">Clear log</button>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

@code{
    private string Output = "";

    /* ToolbarSettings */
    private List<ToolbarItemModel> Items = new List<ToolbarItemModel>()
    {
        new ToolbarItemModel() { Command = ToolbarCommand.Bold },
        new ToolbarItemModel() { Command = ToolbarCommand.Italic },
        new ToolbarItemModel() { Command = ToolbarCommand.Underline },
        new ToolbarItemModel() { Command = ToolbarCommand.StrikeThrough },
        new ToolbarItemModel() { Command = ToolbarCommand.FontName },
        new ToolbarItemModel() { Command = ToolbarCommand.FontSize },
        new ToolbarItemModel() { Command = ToolbarCommand.FontColor },
        new ToolbarItemModel() { Command = ToolbarCommand.BackgroundColor },
        new ToolbarItemModel() { Command = ToolbarCommand.LowerCase },
        new ToolbarItemModel() { Command = ToolbarCommand.UpperCase },
        new ToolbarItemModel() { Command = ToolbarCommand.SuperScript },
        new ToolbarItemModel() { Command = ToolbarCommand.SubScript },
        new ToolbarItemModel() { Command = ToolbarCommand.Separator },
        new ToolbarItemModel() { Command = ToolbarCommand.Formats },
        new ToolbarItemModel() { Command = ToolbarCommand.Alignments },
        new ToolbarItemModel() { Command = ToolbarCommand.OrderedList },
        new ToolbarItemModel() { Command = ToolbarCommand.UnorderedList },
        new ToolbarItemModel() { Command = ToolbarCommand.Outdent },
        new ToolbarItemModel() { Command = ToolbarCommand.Indent },
        new ToolbarItemModel() { Command = ToolbarCommand.Separator },
        new ToolbarItemModel() { Command = ToolbarCommand.CreateLink },
        new ToolbarItemModel() { Command = ToolbarCommand.Image },
        new ToolbarItemModel() { Command = ToolbarCommand.CreateTable },
        new ToolbarItemModel() { Command = ToolbarCommand.Separator },
        new ToolbarItemModel() { Command = ToolbarCommand.ClearFormat },
        new ToolbarItemModel() { Command = ToolbarCommand.Print },
        new ToolbarItemModel() { Command = ToolbarCommand.SourceCode },
        new ToolbarItemModel() { Command = ToolbarCommand.FullScreen },
        new ToolbarItemModel() { Command = ToolbarCommand.Separator },
        new ToolbarItemModel() { Command = ToolbarCommand.Undo },
        new ToolbarItemModel() { Command = ToolbarCommand.Redo }
    };

    /* Methods */
    private void ClearLog()
    {
        this.Output = "";
    }

    /*  Events */
    private void Created(object args)
    {
        this.Output = this.Output + "<span><b>Created</b> event called<hr></span>";
    }
    private void Destroyed(DestroyedEventArgs args)
    {
        this.Output = this.Output + "<span><b>Destroyed</b> event called<hr></span>";
    }
    private void Focus(Syncfusion.Blazor.RichTextEditor.FocusEventArgs args)
    {
        this.Output = this.Output + "<span><b>Focus</b> event called<hr></span>";
    }
    private void Blur(Syncfusion.Blazor.RichTextEditor.BlurEventArgs args)
    {
        this.Output = this.Output + "<span><b>Blur</b> event called<hr></span>";
    }
    private void Change(Syncfusion.Blazor.RichTextEditor.ChangeEventArgs args)
    {
        this.Output = this.Output + "<span><b>ValueChange</b> event called<hr></span>";
    }
    private void ActionBegin(ActionBeginEventArgs args)
    {
        this.Output = this.Output + "<span><b>" + args.RequestType + "</b> command being applied<hr></span>";
    }
    private void ActionComplete(Syncfusion.Blazor.RichTextEditor.ActionCompleteEventArgs args)
    {
        this.Output = this.Output + "<span><b>" + args.RequestType + "</b> command applied<hr></span>";
    }
    private void BeforeDialogOpen(BeforeOpenEventArgs args)
    {
        this.Output = this.Output + "<span><b>OnDialogOpen</b> event called<hr></span>";
    }
    private void DialogOpen(DialogOpenEventArgs args)
    {
        this.Output = this.Output + "<span><b>DialogOpened</b> event called<hr></span>";
    }
    private void BeforeDialogClose(BeforeCloseEventArgs args)
    {
        this.Output = this.Output + "<span><b>OnDialogClose</b> event called<hr></span>";
    }
    private void DialogClose(DialogCloseEventArgs args)
    {
        this.Output = this.Output + "<span><b>DialogClosed</b> event called<hr></span>";
    }
    private void BeforeQuickToolbarOpen(BeforeQuickToolbarOpenArgs args)
    {
        this.Output = this.Output + "<span><b>OnQuickToolbarOpen</b> event called<hr></span>";
    }
    private void QuickToolbarOpen(QuickToolbarEventArgs args)
    {
        this.Output = this.Output + "<span><b>QuickToolbarOpened</b> event called<hr></span>";
    }
    private void QuickToolbarClose(QuickToolbarEventArgs args)
    {
        this.Output = this.Output + "<span><b>QuickToolbarClosed</b> event called<hr></span>";
    }
    private void ResizeStart(ResizeArgs args)
    {
        this.Output = this.Output + "<span><b>OnResizeStart</b> event called<hr></span>";
    }
    private void ResizeStop(ResizeArgs args)
    {
        this.Output = this.Output + "<span><b>OnResizeStop</b> event called<hr></span>";
    }
    private void OnImageSelected(SelectedEventArgs args)
    {
        this.Output = this.Output + "<span><b>OnImageSelected</b> event called<hr></span>";
    }
    private void BeforeUploadImage(ImageUploadingEventArgs args)
    {
        this.Output = this.Output + "<span><b>BeforeUploadImage</b> event called<hr></span>";
    }
    private void OnImageUploadFailed(ImageFailedEventArgs args)
    {
        this.Output = this.Output + "<span><b>OnImageUploadFailed</b> event called<hr></span>";
    }
    private void OnImageUploadSuccess(ImageSuccessEventArgs args)
    {
        this.Output = this.Output + "<span><b>OnImageUploadSuccess</b> event called<hr></span>";
    }
    private void ImageUploadChange(ImageUploadChangeEventArgs args)
    {
        this.Output = this.Output + "<span><b>ImageUploadChange</b> event called<hr></span>";
    }
    private void OnImageRemoving(RemovingEventArgs args)
    {
        this.Output = this.Output + "<span><b>OnImageRemoving</b> event called<hr></span>";
    }
    private void ImageDeleted(AfterImageDeleteEventArgs args)
    {
        this.Output = this.Output + "<span><b>ImageDelete</b> event called<hr></span>";
    }
    private void ToolbarClick(ToolbarClickEventArgs args)
    {
        this.Output = this.Output + "<span><b>OnToolbarClick</b> event called<hr></span>";
    }
}

<style>
    .control-wrapper {
        margin: 0 auto;
    }

    .property-section .right-side {
        padding-left: 10px;
    }

    .property-section .left-side {
        padding: 5px;
        width: 25%
    }

    #EventLog b {
        color: #388e3c;
    }

    #EventLog hr {
        margin: 1px 10px 1px 0px;
        border-top: 1px solid #eee;
    }

    .e-richtexteditor:not(.e-rte-full-screen) {
        max-width: 760px;
        min-width: 200px;
        min-height: 170px;
        max-height: 500px;
    }
</style>